<template>
  <div class="app-container">
    <el-header class="header">
      <el-row type="flex" justify="space-between" align="middle">
        <el-col :span="8">
          <el-menu :default-active="$route.name" class="el-menu-demo" mode="horizontal" router>
            <el-menu-item index="Home" route="/">首页</el-menu-item>
            <el-menu-item index="Tools" route="/tools">计算工具</el-menu-item>
            <el-menu-item index="QuickStart" route="/doc">快速入门</el-menu-item>
            <el-menu-item index="AboutUs" route="/about-us">关于我们</el-menu-item>
          </el-menu>
        </el-col>
        <el-col :span="8" class="centered-search">
          <el-input placeholder="全局搜索" prefix-icon="el-icon-search" v-model="searchQuery" @keyup.enter="handleSearch"></el-input>
        </el-col>
        <el-col :span="2"></el-col>
        <el-col :span="4" class="user-info">
          <div class="user-info-container">
            <el-avatar icon="el-icon-user" :round="true" />
            <span>{{ userName }}</span>
            <el-button type="text">登录</el-button>
            <el-select v-model="language" placeholder="语言选择" size="small" style="margin-left: 10px; width: 100px;">
              <el-option label="中文" value="zh"></el-option>
              <el-option label="英文" value="en"></el-option>
            </el-select>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-main>
      <router-view></router-view>
    </el-main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchQuery: '',
      userName: '用户名',
      language: 'zh', // 默认语言
    };
  },
  methods: {
    handleSearch() {
      console.log('搜索内容:', this.searchQuery);
      // 处理搜索逻辑
    },
  },
};
</script>

<style>
.app-container {
  position: relative; /* 确保 el-header 的 fixed 定位相对于这个容器 */
  height: 100%; /* 设置容器高度，确保 el-main 可以正确铺满剩余空间 */
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000; /* 确保在最上层 */
  background-color: #fff; /* 设置背景色 */
  padding: 10px 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
  border-bottom: none; /* 去掉导航栏下面的线条 */
}

.centered-search {
  display: flex;
  justify-content: center;
}

.user-info {
  display: flex;
  justify-content: flex-end;
}

.user-info-container {
  display: flex;
  align-items: center;
  white-space: nowrap; /* 防止换行 */
  flex-wrap: nowrap; /* 防止换行 */
}
.user-info span {
  margin-left: 10px;
}
</style>
